package kevin.framework.basic.controller;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import kevin.framework.basic.common.emun.XlsCellDataTypeEnum;
import kevin.framework.basic.common.utils.DateUtils;
import kevin.framework.basic.common.xls.CustomCell;
import kevin.framework.basic.common.xls.CustomCellStyle;
import kevin.framework.basic.common.xls.IXlsOperator;
import kevin.framework.basic.common.xls.XlsCellData;
import kevin.framework.basic.common.xls.XlsConvertResult;
import kevin.framework.basic.domain.Log;
import kevin.framework.basic.service.IBaseService;
import kevin.framework.basic.service.ILogService;

/**
 * Generate by Kevin's CodeBuilder
 **/
@Controller
@RequestMapping(value = "/log")
public class LogController extends ResetfulBaseController<Log, String> implements IXlsOperator<Log> {

    ILogService logService;

    @Resource(name = "logService")
    @Override
    public void setService(IBaseService<Log, String> service) {
        this.service = service;
        logService = (ILogService)service;
    }

    /*
     * 页面 views/base/entityPath 文件夹路径
     * ***/
    @Override
    public String setPageModelPath(HttpServletRequest request) {
        // TODO Auto-generated method stub
        return "base" + File.separator + entityPath;
    }

    @Override
    public String getImportSheetName(MultipartHttpServletRequest request) throws Exception {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public int getImportStartRow(MultipartHttpServletRequest request) throws Exception {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public XlsConvertResult<Log> xlsImport(String[] rowData, Map<String, String[]> reqParams,
        Map<Object, Object> extDataMap) throws Exception {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public String setExportSheetName(HttpServletRequest request) throws Exception {
        // TODO Auto-generated method stub
        return "日志列表";
    }

    @Override
    public List<CustomCell[]> setExportSheetTitle(HttpServletRequest request) throws Exception {
        List<CustomCell[]> list = new ArrayList<CustomCell[]>();
        CustomCell[] celssFirst = new CustomCell[1];
        celssFirst[0] = new CustomCell("操作日志记录" + DateUtils.formatCurrentDateTime("yyyy年MM月dd日"), 9, 0);
        list.add(celssFirst);
        CustomCell[] celssSec = new CustomCell[9];
        celssSec[0] = new CustomCell("菜单名称", 0, 1);
        celssSec[1] = new CustomCell("操作说明", 0, 1);
        celssSec[2] = new CustomCell("操作URL", 0, 1);
        celssSec[3] = new CustomCell("操作人", 0, 1);
        celssSec[4] = new CustomCell("ip", 0, 1);
        celssSec[5] = new CustomCell("操作时间", 0, 1);
        celssSec[6] = new CustomCell("操作结果", 0, 1);
        celssSec[7] = new CustomCell("操作数据", 0, 1);
        celssSec[8] = new CustomCell("异常信息", 0, 1);
        list.add(celssSec);
        return list;
    }

    @Override
    public String setExportXlsFileName(HttpServletRequest request) throws Exception {
        // TODO Auto-generated method stub
        return "日志列表" + DateUtils.formatCurrentDateTime("yyyy年MM月dd日");
    }

    @Override
    public XlsCellData[] xlsExport(Log bean, int row) throws Exception {
        String status = "";
        if (bean.getOpstatus().intValue() == 0) {
            status = "失败";
        } else {
            status = "成功";
        }
        XlsCellData[] datas = new XlsCellData[11];
        String menuName = bean.getMenuName();
        if (menuName == null) {
            menuName = "";
        }
        String operateData = bean.getOperateData();
        if (operateData == null) {
            operateData = "";
        }
        String exception = bean.getException();
        if (exception == null) {
            exception = "";
        }
        datas[0] = XlsCellData.getXlsCellData(menuName, XlsCellDataTypeEnum.cString);
        datas[1] = XlsCellData.getXlsCellData(bean.getContent(), XlsCellDataTypeEnum.cString);
        datas[2] = XlsCellData.getXlsCellData(bean.getUrl(), XlsCellDataTypeEnum.cString);
        datas[3] = XlsCellData.getXlsCellData(bean.getCreateUser(), XlsCellDataTypeEnum.cString);
        datas[4] = XlsCellData.getXlsCellData(bean.getOperateIp(), XlsCellDataTypeEnum.cString);
        datas[5] = XlsCellData.getXlsCellData(bean.getCreateTime(), XlsCellDataTypeEnum.cString);
        datas[6] = XlsCellData.getXlsCellData(status, XlsCellDataTypeEnum.cString);
        datas[7] = XlsCellData.getXlsCellData(operateData, XlsCellDataTypeEnum.cString);
        datas[8] = XlsCellData.getXlsCellData(exception, XlsCellDataTypeEnum.cString);
        return datas;
    }

    @Override
    public CustomCellStyle createHeaderCellStyle(String title, int rowIndex) throws Exception {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public CustomCellStyle createBodyCellStyle(Log bean, XlsCellData cellData, String colTitle) throws Exception {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public XlsCellData[] onSheetCreateCompleted(Object[] dataArr, int rowCount, int rowNum) throws Exception {
        // TODO Auto-generated method stub
        return null;
    }

}
